package com.ibeeking.gmc.global.g.rest.controller.v1;

import com.ibeeking.gmc.global.g.rest.service.IGroupService;
import com.ibeeking.found.common.annotation.LoginUser;
import com.ibeeking.found.common.entity.CurrentUser;
import com.ibeeking.gmc.global.service.common.param.GroupParam;
import com.ibeeking.gmc.global.service.common.query.GroupPageQuery;
import com.ibeeking.gmc.global.service.common.query.GroupQuery;
import com.ibeeking.gmc.global.service.common.vo.GroupPageVO;
import com.ibeeking.gmc.global.service.common.vo.GroupVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.BaseValidationGroup;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/g/group/v1")
public class GroupController {

    @Resource
    private IGroupService groupService;

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "分页查询集团列表")
    @PostMapping(value = "/pageList")
    public Page<GroupPageVO> pageList(@RequestBody GroupPageQuery groupPageQuery) {
        return this.groupService.pageList(groupPageQuery);
    }

    @Log(logType = OperateLogTypeEnum.QUERY,describe = "根据id查询集团详情")
    @PostMapping(value = "/view/{id}")
    public GroupVO view(@PathVariable("id") Long id) {
        return this.groupService.view(id);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "修改集团信息")
    @PostMapping(value = "/modify")
    public Boolean modify(@LoginUser CurrentUser currentUser, @RequestBody @Validated(BaseValidationGroup.Update.class) GroupParam groupParam){
        groupParam.setModifyBy(currentUser.getId());
        return this.groupService.modify(groupParam);
    }

    @Log(logType = OperateLogTypeEnum.SAVE,describe = "新增集团信息")
    @PostMapping(value = "/add")
    public Boolean add(@LoginUser CurrentUser currentUser,@RequestBody @Validated(BaseValidationGroup.Insert.class) GroupParam groupParam){
        groupParam.setCreateBy(currentUser.getId()).setModifyBy(currentUser.getId());
        return this.groupService.add(groupParam);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY,describe = "启用/禁用 集团")
    @PostMapping(value = "/changeStatus/{id}/{status}")
    public Boolean changeStatus(@LoginUser CurrentUser currentUser, @PathVariable("id") Long id, @PathVariable("status") Integer status){
        return this.groupService.changeStatus(id,status,currentUser.getId());
    }

    @Log(logType = OperateLogTypeEnum.DEL,describe = "删除集团")
    @PostMapping(value = "/del/{id}")
    public Boolean del(@PathVariable("id") Long id){
        return this.groupService.del(id);
    }



    @Log(logType = OperateLogTypeEnum.QUERY, describe = "有效集团列表查询")
    @PostMapping(value = "/list")
    public List<GroupVO> list(@RequestBody GroupQuery groupQuery) {
        return groupService.list(groupQuery);
    }






}
